package leetcode100;

public class lc015 {
    public static void main(String[] args) {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2,node1);
        ListNode node3 = new ListNode(3,node2);
        ListNode node4 = new ListNode(4,node3);
        ListNode node5 = new ListNode(5,node4);
        node1.next = null;
        boolean flag = hasCycle(node1);
        System.out.println("flag = " + flag);


    }

    public static boolean hasCycle(ListNode head) {
        if (head ==null) return false;
        ListNode slowNode = head;
        ListNode fastNode = head;

        while(fastNode!=null && fastNode.next!=null) {
            slowNode = slowNode.next;
            fastNode = fastNode.next.next;
            if (slowNode==fastNode) {
                return true;
            }

        }
        return false;
    }


}
